Page({
  data: {
    balance: 1000, 
    goodsList: [
      {
        id: 1,
        name: '台灯',
        image: 'https://example.com/lamp.jpg',
        points: 200
      },
      {
        id: 2,
        name: '笔记本',
        image: 'https://example.com/notebook.jpg',
        points: 500
      },
      {
        id: 3,
        name: '保温杯',
        image: 'https://example.com/bottle.jpg',
        points: 300
      }
    ]
  },

  // 兑换商品
  exchange: function (e) {
    const goodsId = e.currentTarget.dataset.id;
    const goods = this.data.goodsList.find(item => item.id === goodsId);

    if (this.data.balance >= goods.points) {
      wx.showModal({
        title: '兑换确认',
        content: `确定要兑换 ${goods.name} 吗？`,
        success: (res) => {
          if (res.confirm) {
            // 扣除积分
            this.setData({
              balance: this.data.balance - goods.points
            });

            wx.showToast({
              title: '兑换成功',
              icon: 'success'
            });
          }
        }
      });
    } else {
      wx.showToast({
        title: '积分不足',
        icon: 'none'
      });
    }
  }
});